package core.handler;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.*;

/**
 * HashMap 结果集
 *
 * @author Feny
 * @date Created in 2022/4/26
 */
public class ColumnMapRowMapper implements RowMapper<Map<String, Object>> {
    @Override
    public Map<String, Object> mapRow(ResultSet rs) throws SQLException {
        ResultSetMetaData rsmd = rs.getMetaData();
        int columnCount = rsmd.getColumnCount();

        Map<String, Object> result = new LinkedHashMap<>(columnCount);
        for (int i = 1; i <= columnCount; i++) {
            result.putIfAbsent(getColumn(rsmd, i), rs.getObject(i));
        }
        return result;
    }
}
